package com.zmn.oms.services.impl.shop;

import com.zmn.oms.model.entity.shop.OrderExternalShop;
import com.zmn.oms.persistence.interfaces.shop.OrderExternalShopDao;
import com.zmn.oms.services.interfaces.shop.OrderExternalShopService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wangyanci
 * @since 2022-08-30
 */
@Service
public class OrderExternalShopServiceImpl implements OrderExternalShopService {

    @Resource
    private OrderExternalShopDao orderExternalShopDao;

    @Override
    public int insert(OrderExternalShop orderExternalShop) {
        Objects.requireNonNull(orderExternalShop, "添加对象不能为空");
        return orderExternalShopDao.insert(orderExternalShop);
    }

    @Override
    public int updateById(OrderExternalShop orderExternalShop) {
        Objects.requireNonNull(orderExternalShop, "修改对象不能为空");
        return orderExternalShopDao.updateById(orderExternalShop);
    }

    @Override
    public OrderExternalShop findByOrderIdAndWorkId(Long orderId, Long workId) {
        return orderExternalShopDao.findByOrderIdAndWorkId(orderId, workId);
    }

    @Override
    public void mergeByOrderIdAndWorkId(Long orderId, Long workId, OrderExternalShop orderExternalShop) {
        orderExternalShopDao.deleteByOrderIdAndWorkId(orderId, workId);
        if (Objects.nonNull(orderExternalShop)) {
            orderExternalShopDao.insert(orderExternalShop);
        }
    }
}
